
//  MessageListTableViewCell.m
//  YuTan
//
//  Created by 葛悦彣 on 2024/9/24.
//

#import "MessageListTableViewCell.h"

@interface MessageListTableViewCell ()
@property (nonatomic ,strong) UIImageView * iconimg;
@property (nonatomic ,strong) UILabel * num;
@property (nonatomic ,strong) UILabel * typelab;
@property (nonatomic ,strong) UILabel * msgTime;
@property (nonatomic ,strong) UILabel * content;
@property (nonatomic ,strong) UILabel * createTime;

@end

@implementation MessageListTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    self.contentView.clipsToBounds = YES;
    
    UIView * backview = [UIView new];
    [DTKTool YJ:kwt(10) andView:backview];
    backview.backgroundColor = UIColor.whiteColor;
    [self.contentView addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.offset(kwt(8));
        make.right.offset(kwt(-8));
        make.bottom.offset(kwt(-8));
    }];
    
    UIImageView * iconimg = kimageView(@"");
    self.iconimg = iconimg;
    [backview addSubview:iconimg];
    [iconimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(12));
        make.top.offset(kwt(14));
        make.width.height.offset(kwt(26));
    }];
    
    UILabel * num = [DTKTool labelWithText:@" " andFont:kFont(12) andTextColor:UIColor.whiteColor];
    self.num = num;
    num.textAlignment = NSTextAlignmentCenter;
    num.backgroundColor = KcolorHex(@"#EC6139");
    [DTKTool YJ:kwt(7.5) andView:num];
    [backview addSubview:num];
    [num mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(iconimg.mas_right);
        make.centerY.equalTo(iconimg.mas_top);
        make.width.height.offset(kwt(15));
    }];
    UILabel * typelab = [DTKTool labelWithText:@"-" andFont:kCFont(17) andTextColor:KcolorHex(@"#222222")];
    self.typelab = typelab;
    [backview addSubview:typelab];
    [typelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(iconimg);
        make.left.offset(kwt(46));
    }];
    
    UILabel * msgTime = [DTKTool labelWithText:@"-" andFont:kFont(15) andTextColor:KcolorHex(@"#7D7D7D")];
    self.msgTime = msgTime;
    [backview addSubview:msgTime];
    [msgTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(iconimg);
        make.right.offset(kwt(-12));
    }];
    
    
    UILabel * content = [DTKTool labelWithText:@"-" andFont:kFont(15) andTextColor:KcolorHex(@"#222222")];
    self.content = content;
    content.numberOfLines = 0;
    [backview addSubview:content];
    [content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(52));
        make.left.offset(kwt(12));
        make.width.offset(kwt(335));
    }];
    
    UIView * line = [UIView new];
    line.backgroundColor = KcolorHex(@"#F5F5F5");
    [backview addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(0.5);
        make.bottom.offset(kwt(-39));
        make.left.offset(kwt(12));
        make.right.offset(kwt(-12));
    }];
    
    
    UILabel * createTime = [DTKTool labelWithText:@"查看详情" andFont:kFont(15) andTextColor:KcolorHex(@"#7D7D7D")];
    [backview addSubview:createTime];
    self.createTime = createTime;
    [createTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(15));
        make.bottom.offset(kwt(-12));
        make.left.offset(kwt(12));
    }];
    
  
    
    UIImageView * tempimg = kimageView(@"template_enter");
    [backview addSubview:tempimg];
    [tempimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-12));
        make.centerY.equalTo(createTime);
        make.width.height.offset(kwt(15));

    }];
    
    UILabel * temp = [DTKTool labelWithText:@"查看详情" andFont:kFont(15) andTextColor:KcolorHex(@"#7D7D7D")];
    [backview addSubview:temp];
    [temp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(15));
        make.bottom.offset(kwt(-12));
        make.right.equalTo(tempimg.mas_left).offset(kwt(-10));
    }];
}


- (void)setModel:(MessageModel *)model{
    _model = model;
    self.num.hidden = model.read;
    self.iconimg.image = [UIImage imageNamed:model.typeimg];
    self.typelab.text = model.typelab;
    self.msgTime.text = model.msgTime;
    self.content.text = model.content;
    self.createTime.text = model.createTime;
    
}
@end
